const fs = require('fs')

try {
  const content = fs.readFileSync('init-database.sql', 'utf8')
  console.log('文件总字符数:', content.length)

  // 检查是否有分号
  const semicolonCount = (content.match(/;/g) || []).length
  console.log('分号数量:', semicolonCount)

  // 先分割
  const splitStatements = content.split(';')
  console.log('分割后语句数量:', splitStatements.length)

  // 再trim
  const trimmedStatements = splitStatements.map(s => s.trim())
  console.log(
    'trim后非空语句数量:',
    trimmedStatements.filter(s => s.length > 0).length
  )

  // 检查注释过滤
  const nonCommentStatements = trimmedStatements.filter(
    s => s.length > 0 && !s.startsWith('--')
  )
  console.log('过滤注释后语句数量:', nonCommentStatements.length)

  console.log('\n前5条非注释语句:')
  nonCommentStatements.slice(0, 5).forEach((s, i) => {
    console.log(`${i + 1}: "${s.substring(0, 50)}..."`)
  })

  // 检查是否有CREATE TABLE语句
  const createTableStatements = nonCommentStatements.filter(s =>
    s.toLowerCase().includes('create table')
  )
  console.log(`\nCREATE TABLE语句数量: ${createTableStatements.length}`)
} catch (error) {
  console.error('读取SQL文件失败:', error.message)
}
